package com.jerei.crm.controller;

import com.jerei.crm.service.ex.*;
import com.jerei.crm.util.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    public JsonResult<Void> handleException(Throwable ex){
        JsonResult<Void> json=new JsonResult<>(ex);
        if (ex instanceof InsertException) {
            json.setState(5000);
        }else if(ex instanceof PasswordNotMatchException){
            json.setState(4002);
        }else if(ex instanceof SelectException){
            json.setState(4004);
        } else if (ex instanceof UpdateException) {
            json.setState(5001);
        } else if(ex instanceof UserNotFoundException){
            json.setState(4001);
        }else if(ex instanceof DeleteException){
            json.setState(4003);
        }
        return json;
    }
}
